#!/bin/sh
#安装python3.7.0

#python环境
apt install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev

PYdir='/usr/local/opt/python-3.7.0/'
wget -O Python-3.7.0.tar.xz https://gitee.com/ksaos/public/raw/master/Raspberrypi/Python/Python-3.7.0.tgz
tar xvf Python-3.7.0.tgz
cd /root/Python-3.7.0 && ./configure --prefix=${PYdir} --with-ssl && make && make install

rm -f /usr/bin/pydoc3.7
rm -f /usr/bin/python3.7
rm -f /usr/bin/python3.7m
rm -f /usr/bin/pyvenv-3.7
rm -f /usr/bin/pip3.7
rm -f /usr/bin/python
rm -f /usr/bin/pip

sudo ln -s ${PYdir}/bin/pydoc3.7 /usr/bin/pydoc3.7
sudo ln -s ${PYdir}/bin/python3.7 /usr/bin/python3.7
sudo ln -s ${PYdir}/bin/python3.7m /usr/bin/python3.7m
sudo ln -s ${PYdir}/bin/pyvenv-3.7 /usr/bin/pyvenv-3.7
sudo ln -s ${PYdir}/bin/pip3.7 /usr/bin/pip3.7
sudo ln -s ${PYdir}/bin/python3.7 /usr/bin/python
sudo ln -s ${PYdir}/bin/pip3.7 /usr/bin/pip

#修改pip源
pipConfFile='/root/.pip/'
mkdir $pipConfFile

cat > ${pipConfFile}/pip.conf << EOF
[global] 
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF